%option noyywrap
%{
/*****************声明和选项设置  begin*****************/
#include <stdio.h>
#include <stdlib.h>

#include "syntax_tree.h"
#include "syntax_analyzer.h"

int lines=1;
int pos_start;
int pos_end;

void pass_node(char *text){
     yylval.node = new_syntax_tree_node(text);
}

/*****************声明和选项设置  end*****************/

%}

letter [a-zA-Z]
digit [0-9]
ID {letter}+
INTEGER {digit}+
FLOATPOINT (({digit}+\.)|({digit}*\.{digit}+))
COMMENT [/][*][^*]*[*]+([^*/][^*]*[*]+)*[/]
COMMENT_BEGIN "/*"
COMMENT_END "*/"

%%
 /* to do for students */
 /* two cases for you, pass_node will send flex's token to bison */
{COMMENT} {pos_start = pos_end; pos_end += strlen(yytext);}

\+ 	{pos_start = pos_end; pos_end += 1; pass_node(yytext); return ADD;}
\- {pos_start = pos_end; pos_end += 1; pass_node(yytext); return MINUS;}
\* {pos_start = pos_end; pos_end += 1; pass_node(yytext); return MUL;}
"/" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return DIV;}
"<" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return LESS;}
"<=" {pos_start = pos_end; pos_end += 2; pass_node(yytext); return EQLESS;}
">" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return MORE;}
">=" {pos_start = pos_end; pos_end += 2; pass_node(yytext); return EQMORE;}
"==" {pos_start = pos_end; pos_end += 2; pass_node(yytext); return EQ;}
"!=" {pos_start = pos_end; pos_end += 2; pass_node(yytext); return NEQ;}
"=" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return EVA;}
";" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return SEM;}
"," {pos_start = pos_end; pos_end += 1; pass_node(yytext); return COMMA;}
"(" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return LBRA;}
")" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return RBRA;}
"[" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return LMBRA;}
"]" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return RMBRA;}
"{" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return LLBRA;}
"}" {pos_start = pos_end; pos_end += 1; pass_node(yytext); return RLBRA;}
" " {pos_start = pos_end; pos_end += 1;}
\n {pos_start = pos_end; pos_end += 1;lines++;}
\t {pos_start = pos_end; pos_end += 1;}
\r {pos_start = pos_end; pos_end += 1;}

"else" {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return ELSE;}
"if" {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return IF;}
"int" {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return INT;}
"return" {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return RETURN;}
"void" {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return VOID;}
"while" {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return WHILE;}
"float" {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return FLOAT;}


{ID} {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return ID;}
{INTEGER} {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return INTEGER;}
{FLOATPOINT} {pos_start = pos_end; pos_end += strlen(yytext);pass_node(yytext);return FLOATPOINT;}

. { pos_start = pos_end; pos_end++; return ERROR; }

 /****请在此补全所有flex的模式与动作  end******/
%%
